/*
 * Copyright (c) 2011 Norbert Kopcsek
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.modulr.bundle {

	import flash.events.Event;

	/**
	 * A BundleEvent object is dispatched whenever a bundle event occur.
	 *
	 * Possible events are:
	 * - INSTALLED
	 * - LOADING
	 * - STARTING
	 * - STOPPING
	 * - ACTIVE
	 * - ERROR
	 *
	 * If you are interested in bundle events, you can register a IBundleListener using the IBundleContext.
	 *
	 * @see org.modulr.bundle.Bundle
	 * @see org.modulr.bundle.BundleLoader
	 * @see org.modulr.bundle.IBundleListener
	 *
	 * @author Norbert Kopcsek
	 */
	public class BundleEvent extends Event {


		//------------------------------------------------------------------------------
		//
		//   Statics 
		//
		//------------------------------------------------------------------------------

		/**
		 * A bundle has been started and is now active.
		 */
		public static const ACTIVE:String = "active";

		/**
		 * An error has occured while loading the bundle.
		 */
		public static const ERROR:String = "error";

		/**
		 * A bundle has been installed. It is ready to be loaded.
		 */
		public static const INSTALLED:String = "installed";

		/**
		 * A bundle is being loaded.
		 */
		public static const LOADING:String = "loading";

		/**
		 * A bundle is being started. The framework now calls the start method of the bundle activator.
		 */
		public static const STARTING:String = "starting";

		/**
		 * A bundle is being stopped. The framework now calls the stop method of the bundle activator.
		 */
		public static const STOPPING:String = "stopping";


		//------------------------------------------------------------------------------
		//
		//   Constructor 
		//
		//------------------------------------------------------------------------------

		public function BundleEvent( type:String, bundle:Bundle ) {
			super( type, false, false );
			_bundle = bundle;
		}


		//------------------------------------------------------------------------------
		//
		//   Properties (Getter/Setter) 
		//
		//------------------------------------------------------------------------------

		//--------------------------------------
		// bundle 
		//--------------------------------------

		/**
		 * The bundle dispatching this event.
		 */
		public function get bundle():Bundle {
			return _bundle;
		}


		//------------------------------------------------------------------------------
		//
		//   Protected fields 
		//
		//------------------------------------------------------------------------------

		/**
		 * @private
		 */
		private var _bundle:Bundle;


		//------------------------------------------------------------------------------
		//
		//   Overridden methods 
		//
		//------------------------------------------------------------------------------

		/**
		 * @inherit
		 */
		override public function clone():Event {
			var event:BundleEvent = new BundleEvent( type, bundle );
			return event;
		}
	}
}

